<template>
  <div class="craving-log-container">
    <div class="page-header">
      <h1>烟瘾记录</h1>
      <p>记录和分析您的烟瘾情况，帮助更好地应对</p>
    </div>

    <!-- 快速记录 -->
    <div class="quick-log-section">
      <h2><i class="fas fa-exclamation-triangle"></i> 快速记录烟瘾</h2>
      <div class="quick-log-card">
        <form @submit.prevent="quickLog" class="quick-log-form">
          <div class="quick-inputs">
            <div class="intensity-input">
              <label>烟瘾强度</label>
              <div class="intensity-slider">
                <input v-model.number="quickForm.intensity" type="range" min="1" max="10" step="1" class="slider" />
                <span class="intensity-value">{{ quickForm.intensity }}/10</span>
              </div>
            </div>
            
            <div class="trigger-select">
              <label>触发因素</label>
              <select v-model="quickForm.trigger" required>
                <option value="">选择触发因素</option>
                <option value="stress">压力</option>
                <option value="boredom">无聊</option>
                <option value="social">社交场合</option>
                <option value="alcohol">饮酒</option>
                <option value="coffee">咖啡</option>
                <option value="meal">餐后</option>
                <option value="work">工作</option>
                <option value="other">其他</option>
              </select>
            </div>
          </div>
          
          <button type="submit" class="quick-log-btn" :disabled="loading">
            {{ loading ? '记录中...' : '立即记录' }}
          </button>
        </form>
      </div>
    </div>

    <!-- 详细记录 -->
    <div class="detailed-log-section">
      <div class="section-header">
        <h2>详细记录</h2>
        <button @click="showDetailedForm = !showDetailedForm" class="toggle-btn">
          {{ showDetailedForm ? '隐藏表单' : '详细记录' }}
        </button>
      </div>

      <div v-if="showDetailedForm" class="detailed-form-card">
        <form @submit.prevent="saveDetailedLog" class="detailed-form">
          <div class="form-grid">
            <div class="form-group">
              <label for="intensity">烟瘾强度 (1-10)</label>
              <div class="slider-group">
                <input id="intensity" v-model.number="detailedForm.intensity" type="range" min="1" max="10" step="1" class="slider" required />
                <span class="slider-value">{{ detailedForm.intensity }}/10</span>
              </div>
            </div>

            <div class="form-group">
              <label for="trigger">触发因素</label>
              <select id="trigger" v-model="detailedForm.trigger" required>
                <option value="">选择触发因素</option>
                <option value="stress">压力</option>
                <option value="boredom">无聊</option>
                <option value="social">社交场合</option>
                <option value="alcohol">饮酒</option>
                <option value="coffee">咖啡</option>
                <option value="meal">餐后</option>
                <option value="work">工作</option>
                <option value="other">其他</option>
              </select>
            </div>

            <div class="form-group">
              <label for="duration">持续时间 (分钟)</label>
              <input id="duration" v-model.number="detailedForm.duration_minutes" type="number" min="1" max="300" placeholder="例如：5" required />
            </div>

            <div class="form-group">
              <label for="successful">是否成功抵御</label>
              <select id="successful" v-model="detailedForm.successful" required>
                <option value="">请选择</option>
                <option value="true">成功抵御</option>
                <option value="false">没有抵御</option>
              </select>
            </div>
          </div>

          <div class="form-group">
            <label for="coping-method">应对方法</label>
            <textarea id="coping-method" v-model="detailedForm.coping_method" rows="3" placeholder="描述您使用的应对方法..." required></textarea>
          </div>

          <div class="form-group">
            <label for="notes">备注</label>
            <textarea id="notes" v-model="detailedForm.notes" rows="2" placeholder="记录当时的情况、感受等..."></textarea>
          </div>

          <div class="form-actions">
            <button type="button" @click="resetDetailedForm" class="reset-btn">重置</button>
            <button type="submit" class="save-btn" :disabled="loading">{{ loading ? '保存中...' : '保存记录' }}</button>
          </div>
        </form>
      </div>
    </div>

    <!-- 统计概览 -->
    <div class="stats-overview">
      <h2>烟瘾统计</h2>
      <div class="stats-cards">
        <div class="stat-card">
          <div class="stat-icon">📊</div>
          <div class="stat-content">
            <h3>{{ totalCravings }}</h3>
            <p>总记录数</p>
          </div>
        </div>
        
        <div class="stat-card">
          <div class="stat-icon">✅</div>
          <div class="stat-content">
            <h3>{{ successfulCravings }}</h3>
            <p>成功抵御</p>
          </div>
        </div>
        
        <div class="stat-card">
          <div class="stat-icon">📈</div>
          <div class="stat-content">
            <h3>{{ successRate }}%</h3>
            <p>成功率</p>
          </div>
        </div>
        
        <div class="stat-card">
          <div class="stat-icon">⭐</div>
          <div class="stat-content">
            <h3>{{ averageIntensity }}</h3>
            <p>平均强度</p>
          </div>
        </div>
      </div>
    </div>

    <!-- 历史记录 -->
    <div class="history-section">
      <div class="section-header">
        <h2>历史记录</h2>
        <div class="filter-controls">
          <select v-model="filterDays" @change="loadCravingLogs">
            <option value="7">最近7天</option>
            <option value="30">最近30天</option>
            <option value="90">最近90天</option>
          </select>
        </div>
      </div>

      <div v-if="cravingLogs.length === 0" class="empty-state">
        <p>暂无烟瘾记录</p>
      </div>

      <div v-else class="logs-list">
        <div v-for="log in cravingLogs" :key="log.id" class="log-item">
          <div class="log-header">
            <div class="log-time">
              <span class="date">{{ formatDate(log.datetime) }}</span>
              <span class="time">{{ formatTime(log.datetime) }}</span>
            </div>
            
            <div class="log-intensity">
              <span class="intensity-badge" :class="getIntensityClass(log.intensity)">
                {{ log.intensity }}/10
              </span>
            </div>
          </div>

          <div class="log-content">
            <div class="log-details">
              <span class="trigger-info">触发因素: {{ getTriggerLabel(log.trigger) }}</span>
              <span class="duration-info">持续: {{ log.duration_minutes }}分钟</span>
              <span :class="['result-info', log.successful ? 'success' : 'failed']">
                {{ log.successful ? '✅ 成功抵御' : '❌ 未能抵御' }}
              </span>
            </div>

            <div v-if="log.coping_method" class="coping-method">
              <strong>应对方法:</strong> {{ log.coping_method }}
            </div>

            <div v-if="log.notes" class="log-notes">
              <strong>备注:</strong> {{ log.notes }}
            </div>
          </div>

          <div class="log-actions">
            <button @click="editLog(log)" class="edit-btn">编辑</button>
            <button @click="deleteLog(log.id)" class="delete-btn">删除</button>
          </div>
        </div>
      </div>
    </div>

    <!-- 提示信息 -->
    <div v-if="error" class="error-message">{{ error }}</div>
    <div v-if="successMessage" class="success-message">{{ successMessage }}</div>
  </div>
</template>

<script>
import { cravingLogApi } from '../api/index.js'

export default {
  name: 'CravingLogView',
  data() {
    return {
      cravingLogs: [],
      showDetailedForm: false,
      loading: false,
      error: '',
      successMessage: '',
      filterDays: '30',
      quickForm: {
        intensity: 5,
        trigger: ''
      },
      detailedForm: {
        intensity: 5,
        trigger: '',
        duration_minutes: '',
        successful: '',
        coping_method: '',
        notes: ''
      },
      triggerOptions: {
        stress: '压力',
        boredom: '无聊',
        social: '社交场合',
        alcohol: '饮酒',
        coffee: '咖啡',
        meal: '餐后',
        work: '工作',
        other: '其他'
      }
    }
  },

  computed: {
    totalCravings() {
      return this.cravingLogs.length
    },
    successfulCravings() {
      return this.cravingLogs.filter(log => log.successful).length
    },
    successRate() {
      if (this.totalCravings === 0) return 0
      return Math.round((this.successfulCravings / this.totalCravings) * 100)
    },
    averageIntensity() {
      if (this.totalCravings === 0) return 0
      const total = this.cravingLogs.reduce((sum, log) => sum + log.intensity, 0)
      return (total / this.totalCravings).toFixed(1)
    }
  },

  async mounted() {
    await this.loadCravingLogs()
  },

  methods: {
    async loadCravingLogs() {
      this.loading = true
      this.error = ''
      
      try {
        console.log('加载烟瘾记录...')
        await new Promise(resolve => setTimeout(resolve, 800))
        
        this.cravingLogs = [
          {
            id: 1,
            datetime: '2024-09-07T14:30:00',
            intensity: 7,
            trigger: 'stress',
            duration_minutes: 15,
            successful: true,
            coping_method: '深呼吸10次，然后喝了一杯水',
            notes: '工作压力大，但成功抵御了'
          },
          {
            id: 2,
            datetime: '2024-09-06T16:45:00',
            intensity: 5,
            trigger: 'coffee',
            duration_minutes: 8,
            successful: true,
            coping_method: '立即去散步5分钟',
            notes: '喝咖啡后想吸烟，散步很有效'
          },
          {
            id: 3,
            datetime: '2024-09-05T20:00:00',
            intensity: 9,
            trigger: 'social',
            duration_minutes: 20,
            successful: false,
            coping_method: '尝试深呼吸，但没有坚持',
            notes: '朋友聚会，看到别人吸烟没能控制住'
          }
        ]
        
      } catch (error) {
        console.error('加载记录失败:', error)
        this.error = '加载记录失败，请稍后重试'
      } finally {
        this.loading = false
      }
    },

    async quickLog() {
      if (!this.quickForm.trigger) {
        this.error = '请选择触发因素'
        return
      }

      this.loading = true
      this.error = ''
      
      try {
        console.log('快速记录烟瘾:', this.quickForm)
        await new Promise(resolve => setTimeout(resolve, 1000))
        
        const newLog = {
          id: Date.now(),
          datetime: new Date().toISOString(),
          intensity: this.quickForm.intensity,
          trigger: this.quickForm.trigger,
          duration_minutes: 5,
          successful: true,
          coping_method: '快速记录',
          notes: ''
        }
        
        this.cravingLogs.unshift(newLog)
        this.quickForm = { intensity: 5, trigger: '' }
        this.successMessage = '烟瘾记录已保存！'
        
        setTimeout(() => { this.successMessage = '' }, 3000)
        
      } catch (error) {
        console.error('记录失败:', error)
        this.error = '记录失败，请稍后重试'
      } finally {
        this.loading = false
      }
    },

    async saveDetailedLog() {
      this.loading = true
      this.error = ''
      
      try {
        const logData = {
          ...this.detailedForm,
          successful: this.detailedForm.successful === 'true'
        }
        
        console.log('保存详细记录:', logData)
        await new Promise(resolve => setTimeout(resolve, 1000))
        
        const newLog = {
          id: Date.now(),
          datetime: new Date().toISOString(),
          ...logData
        }
        
        this.cravingLogs.unshift(newLog)
        this.resetDetailedForm()
        this.showDetailedForm = false
        this.successMessage = '详细记录已保存！'
        
        setTimeout(() => { this.successMessage = '' }, 3000)
        
      } catch (error) {
        console.error('保存失败:', error)
        this.error = '保存失败，请稍后重试'
      } finally {
        this.loading = false
      }
    },

    resetDetailedForm() {
      this.detailedForm = {
        intensity: 5,
        trigger: '',
        duration_minutes: '',
        successful: '',
        coping_method: '',
        notes: ''
      }
    },

    editLog(log) {
      console.log('编辑记录:', log)
      this.successMessage = '编辑功能开发中...'
      setTimeout(() => { this.successMessage = '' }, 3000)
    },

    async deleteLog(logId) {
      if (!confirm('确定要删除这条记录吗？')) return

      try {
        console.log('删除记录:', logId)
        await new Promise(resolve => setTimeout(resolve, 500))
        
        this.cravingLogs = this.cravingLogs.filter(log => log.id !== logId)
        this.successMessage = '记录已删除'
        
        setTimeout(() => { this.successMessage = '' }, 3000)
        
      } catch (error) {
        console.error('删除失败:', error)
        this.error = '删除失败，请稍后重试'
      }
    },

    formatDate(dateString) {
      return new Date(dateString).toLocaleDateString('zh-CN', {
        month: '2-digit',
        day: '2-digit'
      })
    },

    formatTime(dateString) {
      return new Date(dateString).toLocaleTimeString('zh-CN', {
        hour: '2-digit',
        minute: '2-digit'
      })
    },

    getTriggerLabel(trigger) {
      return this.triggerOptions[trigger] || trigger
    },

    getIntensityClass(intensity) {
      if (intensity <= 3) return 'low'
      if (intensity <= 6) return 'medium'
      return 'high'
    }
  }
}
</script>

<style scoped>
.craving-log-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px;
  background: linear-gradient(135deg, #faf0ff 0%, #f0f9ff 100%);
  position: relative;
  overflow: hidden;
  font-family: '方正准圆简体', '站酷快乐体', 'Comic Sans MS', cursive, sans-serif;
}

/* 背景装饰元素 */
.craving-log-container::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-image: 
    radial-gradient(circle at 10% 20%, rgba(255, 198, 255, 0.2) 3px, transparent 3px),
    radial-gradient(circle at 90% 40%, rgba(180, 248, 200, 0.2) 2px, transparent 2px),
    radial-gradient(circle at 40% 80%, rgba(255, 209, 220, 0.2) 4px, transparent 4px),
    radial-gradient(circle at 70% 15%, rgba(162, 210, 255, 0.2) 3px, transparent 3px),
    radial-gradient(circle at 20% 70%, rgba(255, 175, 204, 0.2) 2px, transparent 2px),
    radial-gradient(circle at 85% 25%, rgba(255, 209, 220, 0.2) 3px, transparent 3px);
  background-size: 200px 200px;
  z-index: 0;
}

.craving-log-container > * {
  position: relative;
  z-index: 1;
}

.page-header {
  text-align: center;
  margin-bottom: 30px;
  animation: slideInDown 0.8s ease-out;
}

.page-header h1 {
  color: #444444;
  margin-bottom: 10px;
  font-size: 28px;
  font-weight: 500;
  font-family: '方正准圆简体', '站酷快乐体', 'Comic Sans MS', cursive, sans-serif;
}

.page-header p {
  color: #888888;
  font-size: 16px;
  font-weight: 400;
  font-family: '方正准圆简体', '站酷快乐体', 'Comic Sans MS', cursive, sans-serif;
}

.quick-log-section {
  background: linear-gradient(135deg, #FFAFCC 0%, #FF8FA3 100%);
  color: white;
  border-radius: 20px;
  padding: 25px;
  margin-bottom: 30px;
  border: 2px solid #FF6B6B;
  box-shadow: 0 8px 25px rgba(255, 107, 107, 0.2);
  position: relative;
  overflow: hidden;
  animation: slideInUp 0.8s ease-out;
}

.quick-log-section::after {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 4px;
  background: linear-gradient(90deg, #FF6B6B, #FFAFCC);
  border-radius: 20px 20px 0 0;
}

.quick-log-section h2 {
  margin-bottom: 20px;
  text-align: center;
  font-family: '方正准圆简体', '站酷快乐体', 'Comic Sans MS', cursive, sans-serif;
}

.quick-log-card {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 15px;
  padding: 20px;
  backdrop-filter: blur(5px);
}

.quick-log-form {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.quick-inputs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

.intensity-input,
.trigger-select {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.intensity-input label,
.trigger-select label {
  font-weight: 500;
  opacity: 0.9;
  font-family: '方正准圆简体', '站酷快乐体', 'Comic Sans MS', cursive, sans-serif;
}

.intensity-slider {
  display: flex;
  align-items: center;
  gap: 15px;
}

.slider {
  flex: 1;
  height: 10px;
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.3);
  outline: none;
  cursor: pointer;
  -webkit-appearance: none;
}

.slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: white;
  border: 2px solid #FF6B6B;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0,0,0,0.2);
}

.intensity-value {
  min-width: 50px;
  text-align: center;
  font-weight: bold;
  background: rgba(255, 255, 255, 0.2);
  padding: 5px 10px;
  border-radius: 15px;
  font-family: '方正准圆简体', '站酷快乐体', 'Comic Sans MS', cursive, sans-serif;
}

.trigger-select select {
  padding: 12px;
  border: none;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.9);
  color: #333;
  font-family: '方正准圆简体', '站酷快乐体', 'Comic Sans MS', cursive, sans-serif;
  box-shadow: 0 2px 6px rgba(0,0,0,0.1);
}

.trigger-select select:focus {
  outline: none;
  box-shadow: 0 0 0 2px rgba(255, 107, 107, 0.3);
}

.quick-log-btn {
  background: linear-gradient(135deg, #FFD1DC 0%, #A2D2FF 100%);
  color: white;
  border: none;
  padding: 15px 30px;
  border-radius: 25px;
  cursor: pointer;
  font-size: 16px;
  font-weight: bold;
  align-self: center;
  transition: all 0.3s ease;
  font-family: '方正准圆简体', '站酷快乐体', 'Comic Sans MS', cursive, sans-serif;
  box-shadow: 0 4px 10px rgba(162, 210, 255, 0.3);
}

.quick-log-btn:hover:not(:disabled) {
  transform: translateY(-2px) scale(1.05);
  box-shadow: 0 6px 15px rgba(162, 210, 255, 0.4);
}

.detailed-log-section,
.stats-overview,
.history-section {
  background: rgba(255, 255, 255, 0.9);
  border-radius: 20px;
  padding: 30px;
  margin-bottom: 30px;
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.1);
  border: 2px solid #A2D2FF;
  position: relative;
  overflow: hidden;
  animation: slideInUp 0.8s ease-out;
}

.detailed-log-section::after,
.stats-overview::after,
.history-section::after {
  content: "";
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 4px;
  background: linear-gradient(90deg, #FFD1DC, #A2D2FF);
  border-radius: 0 0 20px 20px;
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 25px;
}

.section-header h2 {
  color: #444444;
  margin: 0;
  font-family: '方正准圆简体', '站酷快乐体', 'Comic Sans MS', cursive, sans-serif;
}

.toggle-btn {
  background: linear-gradient(135deg, #FFD1DC 0%, #A2D2FF 100%);
  color: white;
  border: none;
  padding: 10px 20px;
  border-radius: 20px;
  cursor: pointer;
  font-family: '方正准圆简体', '站酷快乐体', 'Comic Sans MS', cursive, sans-serif;
  transition: all 0.3s ease;
  box-shadow: 0 4px 10px rgba(162, 210, 255, 0.3);
}

.toggle-btn:hover {
  background: linear-gradient(135deg, #A2D2FF 0%, #CDB4DB 100%);
  transform: scale(1.05);
  box-shadow: 0 6px 15px rgba(162, 210, 255, 0.4);
}

.detailed-form-card {
  border: 2px solid #e0e0e0;
  border-radius: 20px;
  padding: 25px;
  margin-top: 20px;
  background: white;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
}

.detailed-form {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 20px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.form-group label {
  font-weight: 500;
  color: #444444;
  font-size: 14px;
  font-family: '方正准圆简体', '站酷快乐体', 'Comic Sans MS', cursive, sans-serif;
}

.form-group input,
.form-group select,
.form-group textarea {
  padding: 12px;
  border: 2px solid #A2D2FF;
  border-radius: 12px;
  font-size: 14px;
  font-family: '方正准圆简体', '站酷快乐体', 'Comic Sans MS', cursive, sans-serif;
  transition: all 0.3s ease;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: #FFD1DC;
  box-shadow: 0 0 0 2px rgba(255, 209, 220, 0.3);
}

.slider-group {
  display: flex;
  align-items: center;
  gap: 15px;
}

.slider-value {
  min-width: 40px;
  text-align: center;
  font-weight: 500;
  color: #A2D2FF;
  font-family: '方正准圆简体', '站酷快乐体', 'Comic Sans MS', cursive, sans-serif;
}

.form-actions {
  display: flex;
  gap: 15px;
  justify-content: flex-end;
  margin-top: 20px;
}

.reset-btn {
  background: #f8f9fa;
  color: #666;
  border: 2px solid #e0e0e0;
  padding: 12px 24px;
  border-radius: 20px;
  cursor: pointer;
  font-family: '方正准圆简体', '站酷快乐体', 'Comic Sans MS', cursive, sans-serif;
  transition: all 0.3s ease;
}

.reset-btn:hover {
  background: #e9ecef;
  transform: scale(1.05);
}

.save-btn {
  background: linear-gradient(135deg, #B4F8C8 0%, #A2D2FF 100%);
  color: white;
  border: none;
  padding: 12px 24px;
  border-radius: 20px;
  cursor: pointer;
  font-family: '方正准圆简体', '站酷快乐体', 'Comic Sans MS', cursive, sans-serif;
  transition: all 0.3s ease;
  box-shadow: 0 4px 10px rgba(162, 210, 255, 0.3);
}

.save-btn:hover:not(:disabled) {
  transform: scale(1.05);
  box-shadow: 0 6px 15px rgba(162, 210, 255, 0.4);
}

.save-btn:disabled {
  background: #ccc;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.stats-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 20px;
}

.stat-card {
  background: rgba(255, 255, 255, 0.9);
  padding: 25px;
  border-radius: 20px;
  display: flex;
  align-items: center;
  gap: 15px;
  border: 2px solid #A2D2FF;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
  transition: all 0.3s cubic-bezier(0.68, -0.55, 0.27, 1.55);
  position: relative;
  overflow: hidden;
}

.stat-card:hover {
  transform: translateY(-5px) scale(1.02);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.1);
}

.stat-card::after {
  content: "";
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 3px;
  background: linear-gradient(90deg, #FFD1DC, #A2D2FF);
  border-radius: 0 0 20px 20px;
}

.stat-icon {
  font-size: 32px;
  width: 60px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.7);
  border-radius: 50%;
  border: 2px solid #A2D2FF;
  box-shadow: inset 0 0 10px rgba(255, 255, 255, 0.5), 0 4px 10px rgba(162, 210, 255, 0.3);
}

.stat-content h3 {
  font-size: 24px;
  font-weight: 500;
  color: #444444;
  margin: 0 0 5px 0;
  font-family: '方正准圆简体', '站酷快乐体', 'Comic Sans MS', cursive, sans-serif;
}

.stat-content p {
  color: #888888;
  margin: 0;
  font-size: 14px;
  font-weight: 300;
  font-family: '方正准圆简体', '站酷快乐体', 'Comic Sans MS', cursive, sans-serif;
}

.filter-controls select {
  padding: 10px 15px;
  border: 2px solid #A2D2FF;
  border-radius: 20px;
  background: white;
  font-family: '方正准圆简体', '站酷快乐体', 'Comic Sans MS', cursive, sans-serif;
  transition: all 0.3s ease;
}

.filter-controls select:focus {
  outline: none;
  border-color: #FFD1DC;
  box-shadow: 0 0 0 2px rgba(255, 209, 220, 0.3);
}

.empty-state {
  text-align: center;
  padding: 40px;
  color: #888888;
  font-family: '方正准圆简体', '站酷快乐体', 'Comic Sans MS', cursive, sans-serif;
}

.logs-list {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.log-item {
  background: white;
  border: 2px solid #e0e0e0;
  border-radius: 20px;
  padding: 20px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
  transition: all 0.3s ease;
  position: relative;
}

.log-item:hover {
  transform: translateY(-3px);
  box-shadow: 0 6px 15px rgba(0, 0, 0, 0.1);
  border-color: #A2D2FF;
}

.log-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 15px;
}

.log-time {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.log-time .date {
  font-weight: 500;
  color: #444444;
  font-family: '方正准圆简体', '站酷快乐体', 'Comic Sans MS', cursive, sans-serif;
}

.log-time .time {
  font-size: 12px;
  color: #888888;
  font-family: '方正准圆简体', '站酷快乐体', 'Comic Sans MS', cursive, sans-serif;
}

.intensity-badge {
  padding: 6px 12px;
  border-radius: 15px;
  font-size: 14px;
  font-weight: bold;
  font-family: '方正准圆简体', '站酷快乐体', 'Comic Sans MS', cursive, sans-serif;
}

.intensity-badge.low {
  background: #d4edda;
  color: #155724;
}

.intensity-badge.medium {
  background: #fff3cd;
  color: #856404;
}

.intensity-badge.high {
  background: #f8d7da;
  color: #721c24;
}

.log-details {
  display: flex;
  flex-wrap: wrap;
  gap: 15px;
  margin-bottom: 10px;
  font-size: 14px;
  font-family: '方正准圆简体', '站酷快乐体', 'Comic Sans MS', cursive, sans-serif;
}

.trigger-info,
.duration-info {
  color: #666;
}

.result-info {
  font-weight: 500;
}

.result-info.success {
  color: #28a745;
}

.result-info.failed {
  color: #dc3545;
}

.coping-method,
.log-notes {
  color: #555;
  font-size: 14px;
  margin-bottom: 8px;
  line-height: 1.4;
  font-family: '方正准圆简体', '站酷快乐体', 'Comic Sans MS', cursive, sans-serif;
}

.log-actions {
  display: flex;
  gap: 10px;
  margin-top: 15px;
}

.edit-btn,
.delete-btn {
  padding: 8px 16px;
  border: 2px solid #e0e0e0;
  border-radius: 12px;
  cursor: pointer;
  font-size: 12px;
  font-family: '方正准圆简体', '站酷快乐体', 'Comic Sans MS', cursive, sans-serif;
  transition: all 0.3s ease;
}

.edit-btn {
  background: #f8f9fa;
  color: #666;
}

.edit-btn:hover {
  background: #e9ecef;
  transform: scale(1.05);
}

.delete-btn {
  background: #f8d7da;
  color: #721c24;
  border-color: #f5c6cb;
}

.delete-btn:hover {
  background: #f5c6cb;
  transform: scale(1.05);
}

.error-message {
  background: #fee;
  color: #c33;
  padding: 15px;
  border-radius: 12px;
  margin-top: 20px;
  text-align: center;
  border: 2px solid #fcc;
  font-family: '方正准圆简体', '站酷快乐体', 'Comic Sans MS', cursive, sans-serif;
}

.success-message {
  background: #efe;
  color: #393;
  padding: 15px;
  border-radius: 12px;
  margin-top: 20px;
  text-align: center;
  border: 2px solid #cfc;
  font-family: '方正准圆简体', '站酷快乐体', 'Comic Sans MS', cursive, sans-serif;
}

/* 动画效果 */
@keyframes slideInUp {
  from {
    transform: translate3d(0, 100%, 0);
    visibility: visible;
  }
  to {
    transform: translate3d(0, 0, 0);
  }
}

@keyframes slideInDown {
  from {
    transform: translate3d(0, -100%, 0);
    visibility: visible;
  }
  to {
    transform: translate3d(0, 0, 0);
  }
}

@media (max-width: 768px) {
  .craving-log-container {
    padding: 15px;
  }
  
  .quick-inputs {
    grid-template-columns: 1fr;
  }
  
  .form-grid {
    grid-template-columns: 1fr;
  }
  
  .stats-cards {
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  }
  
  .section-header {
    flex-direction: column;
    gap: 15px;
    align-items: stretch;
  }
}
</style>